<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
		<title>推广</title>
		<link rel="stylesheet" type="text/css" href="css/common2.css"/>
		<link rel="stylesheet" type="text/css" href="css/text.css"/>
	</head>
	<body>
		<div class="main">
			<form action="" id="form" method="post">
				<div class="input-box"><input type="text" name="" id="phone" placeholder="请输入手机号" value="" />
					<input type="hidden" name="wxUrl" id="wxUrl" placeholder="请输入wxUrl" value="" />
				</div>
				<div class="input-box">
					<input type="text" name="code" id="code" placeholder="请输入验证码" value="" />
					<button class="getCode" type="button">获取验证码</button>
				</div>
				<button class="sub">前往</button>
			</form>
		</div>
		
		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(document).ready(function(){
			  $("#wxUrl").val(getQueryString("wxUrl"));
				var height = $(window).height();
				$('.main').height(height)
				
				$(window).on('resize',function(){
					var height = $(window).height();
					$('.main').height(height)
				})
				$('.getCode').click(function(){
				  if($("#phone").val()==""){
				  	alert("请输入手机号");
				  	return;
				  }
          	$.ajax({
							type: "GET",
							url:"/qr/sendText?phone="+$("#phone").val(),
							cache: false,
							contentType: false,
							processData: false,
							success: function(data) {
									if(data.rel){
									}else{
									  alert(data.msg);
									}
							}
						});


					$(this).attr('disabled',true).css({'background':'#cccccc'})
					var time = 60;
					$('.getCode').text(time + 's重新获取')
					var intv = setInterval(function(){
						time--;
						if(time < 1){
							$('.getCode').text('重新获取')
							clearInterval(intv)
							$('.getCode').attr('disabled',false).css({'background':'#FCB141'})
						} else {
							$('.getCode').text(time + 's重新获取')
						}
					},1000)
				});

				$('#form').submit(function(e) {
					$.ajax({
						type: "get",
						url: "/qr/textWx?wxUrl="+$("#wxUrl").val()+"&code="+$("#code").val()+"&phone="+$("#phone").val(),
						cache: false,
						contentType: false,
						processData: false,
						success: function(data) {
							if(data) {
								var rel = data.rel;
								if(rel){
									location=data.result;
								} else {
									alert(data.msg);
								}

							} else {
								// alert("登陆失败");
								layui.use('layer', function() {
									var layer = layui.layer;
									layer.msg('登陆失败', {
										icon: 5
									})
								})
							}

						}
					});
					e.preventDefault();
				});
			})

			function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return r[2];
    return null;
}
		</script>
	</body>
</html>
